<?php
namespace app\admin\controller;
use think\Request;
use think\Db;
class Staff extends Base {


    /**
    *管理员列表
     */
    public function staffList(){
        $this->isLogin();
       $row = Db::table("staff")->where("staff_del = 0")->select();
       $this->view->assign("row",$row);
        return view();
    }



    /**
    *管理员增加
     */
    public function staffAdd(){
        return view();
    }
    
    /**
    * 写入数据库
     */
    public function staffInset(){
        $this->isLogin();
        $request = Request::instance()->post();
        $staff_name = $request['staff_name'];
        $login_name = $request['login_name'];
        $login_pwd = $request['login_pwd'];
        $staff_photo = $request['staff_photo'];
        $code = rand("1000","9999");
        $no = rand(100000,999999);
        $pwd = md5($login_pwd.$code);
        $time = time();
        $data = [
            "staff_name" => $staff_name,
            "login_pwd" => $pwd,
            "staff_photo" => $staff_photo,
            "staff_no"=> $no,
            "safety_code" => $code,
            "login_name" => $login_name,
            "staff_time" => $time,
            "login_ip" => $_SERVER['REMOTE_ADDR']
        ];
         $row = Db::table('staff')->insert($data);
        if($row >0){
            echo $row;
        }else{
            echo 0;
        }
    }



    /**
    *管理删除
     */
    public function deLstaff(){
        $this->isLogin();
        $request = Request::instance()->get();
        $id = $request['id'];
        $m = new \app\admin\model\Staff();
        $row = $m->delStaff($id);
        if($row){ 
            echo 1;
        }else{
            echo 0;
        }

    }

    /**
     *管理恢复
     */
    public function delTstaff(){
        $this->isLogin();
        $request = Request::instance()->get();
        $id = $request['id'];
        $m = new \app\admin\model\Staff();
        $row = $m->delsStaff($id);
        if($row){
            echo 1;
        }else{
            echo 0;
        }

    }






}